<template>
    <div>
        <div><h1>抽奖记录</h1></div>
        <div>
            <el-form
                :inline="true"
                :model="searchForm"
                class="demo-form-inline"
            >
                <el-form-item label="用户搜索">
                    <el-input
                        v-model="searchForm.keyWord"
                        placeholder="请输入昵称/UID"
                        clearable
                    />
                </el-form-item>
               
                <el-form-item>
                    <el-button type="primary" @click="loadJoinRecordList"
                        >查询</el-button
                    >
                </el-form-item>
            </el-form>
        </div>
        <div>
            <el-table :data="recordList" stripe style="width: 100%">
                <el-table-column prop="recordId" label="ID" width="100" />
                <el-table-column prop="userId" label="UID" width="120" />
                <el-table-column prop="userName" label="微信昵称" width="120" />
                <el-table-column
                    prop="activeName"
                    label="活动名称"
                    width="120"
                />
                <el-table-column
                    prop="userMobile"
                    label="联系方式"
                    width="140"
                />
                <el-table-column
                    prop="activeType"
                    label="活动类型"
                    width="120"
                />
                <el-table-column prop="winName" label="是否中奖" width="100" />
                <el-table-column prop="winProd" label="奖品" width="120" />
                <el-table-column prop="createTime" label="时间" width="160" />
                <el-table-column prop="recordDesc" label="备注" width="180" />
                <el-table-column label="操作" />
            </el-table>
        </div>
        <div style="margin-top: 20px">
            <el-pagination
                v-model:current-page="searchForm.pageNum"
                v-model:page-size="searchForm.pageSize"
                :page-sizes="[2, 4, 6, 8]"
                size="small"
                :background="true"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
            />
        </div>
    </div>
</template>

<script setup lang="ts">
import { getJoinRecord } from "@/api/win";
import { onMounted, ref } from "vue";

// 分页变量
const recordList = ref([]);
const searchForm = ref({
    pageNum: 1,
    pageSize: 2,
    typeId: null, // 活动id
    keyWord: null, // 关键字
});
const total = ref(0);

const handleSizeChange = (val: number) => {
    console.log(`${val} items per page`);
    searchForm.value.pageSize = val;
    loadJoinRecordList();
};
const handleCurrentChange = (val: number) => {
    console.log(`current page: ${val}`);
    searchForm.value.pageNum = val;
    loadJoinRecordList();
};

// 加载抽奖记录列表
const loadJoinRecordList = () => {
    getJoinRecord(searchForm.value).then((res) => {
        if (res.data.code == 200) {
            recordList.value = res.data.data.records;
            total.value = res.data.data.total;
        }
    });
};

// 页面加载钩子函数
onMounted(() => {
    // 获取活动ID
    searchForm.value.typeId = sessionStorage.getItem("activeId");
    // 加载活动列表
    loadJoinRecordList();
});
</script>

<style scoped></style>
